import { paymentSetupList } from '@/api/BusinessScope/paymentSetup'

const seachTableRef = ref(null)
const dialogVisible = ref(false)
const dialogDetail = ref({})
export const usePaymentSetup = () => {
  return {
    seachTableRef,
    dialogVisible,
    dialogDetail,
  }
}

export const useCurd = () => {
  //表格数据
  const tableData = ref([])
  const tableLoading = ref(false)
  const totalPage = ref(0)

  // 搜索
  const handlerSearch = async (data) => {
    try {
      tableLoading.value = true
      const res = await paymentSetupList(data)
      tableData.value = res
      totalPage.value = res.length
    } finally {
      tableLoading.value = false
    }
  }

  const handlerActionDialog = (row={}) => {
    dialogDetail.value = row
    dialogVisible.value = true
  }
  // 表格配置
  const btnLefts = ref([
    {
      label:'新增支付方式',
      type:'primary',
      show:()=>true,
      img:new URL("@/assets/icon/btn-add.png",import.meta.url),
      click:()=>{
        handlerActionDialog()
      }
    },
  ])
  const tableForms = ref([
    {
      type: 'input',
      prop: 'payType',
      placeholder: '支付方式',
      label: '',
      model: '',
    },
    {
      type: 'select',
      prop: "configStatus",
      placeholder: "状态",
      label: "",
      model: "",
      data: [{
        value: true,
        label: '启用'
      }, {
        value: false,
        label: '禁用'
      }]
    },
  ])
  const tableConfig = ref([
    {
      label: '支付方式',
      prop: 'configValue',
      minWidth: 160
    },
    {
      label: '图标',
      prop: 'configImg',
      minWidth: 80,
      type: 'slot',
      slotName: 'icon'
    },
    {
      label: '状态',
      prop: 'enableStatus',
      minWidth: 120,
      type: 'slot',
      slotName: 'state'
    },
    {
      label: '备注',
      prop: 'configDesc',
      minWidth: 422
    },
    {
      label: '创建时间',
      prop: 'createTime',
      minWidth: 240
    },
    {
      type: "action",
      label: '操作',
      prop: 'action',
      minWidth: 120,
      btns: [
        {
          label:()=> '编辑',
          type: 'success',
          show:(row)=>{
            return !row.configDefault
          },
          click: (row)=>{
            handlerActionDialog(row)
          }
        }
      ]
    }
  ])

  return {
    tableConfig,
    tableData,
    tableLoading,
    totalPage,
    handlerSearch,
    btnLefts,
    tableForms
  }
}